package com.youtellv1.service.Impl;

import com.github.pagehelper.PageInfo;
import com.youtellv1.entity.Child;
import com.youtellv1.mapper.ChildMapper;
import com.youtellv1.service.ChildService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ChildServiceImpl implements ChildService {
    @Resource
    private ChildMapper childMapper;

    @Override
    public PageInfo<Child> findChildByPage(int page, int size) {
        int offset = (page - 1) * size;
        List<Child> list = childMapper.findAllChild(offset, size);

        int total = childMapper.childCount();

        PageInfo<Child> pageInfo = new PageInfo<>(list);
        pageInfo.setTotal(total);
        pageInfo.setPageNum(page);
        pageInfo.setPageSize(size);

        return pageInfo;
    }

    @Override
    public Child findChild(Child child) {
        return childMapper.findChild(child);
    }

    @Override
    public Child findById(Integer cid) {
        return childMapper.findById(cid);
    }

    @Override
    public Child findNameByCid(Integer cid) {
        return childMapper.findNameByCid(cid);
    }

    @Override
    public Child findByIdService(Integer cid) {
        return childMapper.findChildById(cid);
    }


    @Override
    public void saveService(Child child) {
        childMapper.save(child);
    }

    @Override
    public void updateFlagService(Integer cid, String flag) {
        childMapper.updateFlag(cid, flag);
    }

    @Override
    public void updateService(Child child) {
        childMapper.update(child);
    }

    @Override
    public void deleteService(Child child) {
        childMapper.delete(child);
    }

    @Override
    public Integer childCountService() {
        return childMapper.childCount();
    }
}
